/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tools;

import com.aptech.bluepumpkin.Prize;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import javax.faces.model.ListDataModel;
import org.primefaces.model.SelectableDataModel;

/**
 *
 * @author Trong Nguyen
 */
public final class PrizeDataModel extends ListDataModel<Prize> implements SelectableDataModel<Prize>, Serializable {

    private HashMap<Integer, Prize> maps = new HashMap<Integer, Prize>();

    public PrizeDataModel(List<Prize> list) {
        super(list);
        List<Prize> lst = (List<Prize>) getWrappedData();
        buildHashMap(lst);
    }

    public PrizeDataModel() {
    }

    public void buildHashMap(List<Prize> list) {
         maps.clear();
        if(null==list||list.isEmpty()){
            return;
        }
      
        for (Prize prize : list) {
            maps.put(prize.getId(), prize);

        }
    }

    @Override
    public Object getRowKey(Prize object) {
        if (null != object) {
            return object.getId();
        } else {
            return null;
        }
    }

    @Override
    public Prize getRowData(String rowKey) {
        Integer id = new Integer(rowKey);
        return maps.get(id);
    }
}
